package com.small.site.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xiaochi
 * @date 2021/11/21 14:04
 * @desc RouteLocator路由配置
 */
@Configuration
public class RouteConfig {
    private static final String URI_PREFIX = "lb://";
    private static final String APPLICATION_BASE_NAME = "small-server-base";
    private static final String APPLICATION_MANAGER_NAME = "small-server-manager";

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder){
        return builder.routes()
                .route(APPLICATION_BASE_NAME, r -> r.path("/api/druid/**").filters(f -> f.stripPrefix(1)).uri(URI_PREFIX+APPLICATION_BASE_NAME))
                .route(APPLICATION_MANAGER_NAME,r -> r.path("/api/manager/**").filters(f -> f.stripPrefix(1)).uri(URI_PREFIX+APPLICATION_MANAGER_NAME))
                .build();
    }
}
